<%@page contentType="text/html"%>  
<%@page pageEncoding="UTF-8"%>  

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>  
<%@taglib uri="http://richfaces.org/a4j" prefix="a4j"%>  
<%@taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   
"http://www.w3.org/TR/html4/loose.dtd">  
<html>
    <head>
        <title>Receber</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="Pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="cache-control" content="no-store">
        <meta http-equiv="expires" content="0">
    </head>
    <script type="ttext/javascript" language="javascript">
        function CheckAll(fmobj) {
            var check = document.getElementById('receberPesq:tblVendaLancamentos:allCheck').checked;
            for (var i=0;i<fmobj.elements.length;i++) {
                var e = fmobj.elements[i];
                if ( (e.type=='checkbox') && (!e<.disabled) ) {
                    e.checked = check;
                }
            }
        }
    </script>
    <style type="text/css"><!--@import url("../../_css/style.css");--></style>
    <body>
        <f:view>
            <t:saveState id="_bean" value="#{ReceberBean}" />
            <h:form id="receberPesq">
                <rich:simpleTogglePanel switchType="client" label="Receber" width="95%">
                    <t:panelGrid columns="4">
                        <t:column width="15%">
                            <h:outputLabel value="Período entre"/>
                        </t:column>
                        <t:column width="35%">
                            <rich:calendar id="dataVencimentoIni" popup="true" datePattern="dd/MM/yyyy" inputSize="7" enableManualInput="false" value="#{ReceberBean.dataVencimentoIni}"/>
                            &nbsp;e&nbsp;
                            <rich:calendar id="dataVencimentoFim" popup="true" datePattern="dd/MM/yyyy" inputSize="7" enableManualInput="false" value="#{ReceberBean.dataVencimentoFim}"/>
                        </t:column>
    
                        <t:column><h:outputLabel value="Forma de Pagamento" for="formaPagamentoId"/>&nbsp;</t:column>
                        <t:column>
                            <h:selectOneMenu id="formaPagamentoSel" value="#{ReceberBean.formaPagamentoSel}" style="width:250px;">
                                <f:selectItem itemValue="" itemLabel=""/>
                                <f:selectItems value="#{ReceberBean.listaFormaPagamentos}"/>
                            </h:selectOneMenu>
                            &nbsp;
                        </t:column>

                        <t:column width="15%"><h:outputLabel value="Mês" for="mesSel"/></t:column>
                        <t:column width="35%">
                            <h:selectOneMenu id="mesSel" value="#{ReceberBean.mesSel}" styleClass="rich-combobox-input">
                                <f:selectItem itemValue="" itemLabel=""/>
                                <f:selectItem itemValue="0" itemLabel="Jan"/>
                                <f:selectItem itemValue="1" itemLabel="Fev"/>
                                <f:selectItem itemValue="2" itemLabel="Mar"/>
                                <f:selectItem itemValue="3" itemLabel="Abr"/>
                                <f:selectItem itemValue="4" itemLabel="Maio"/>
                                <f:selectItem itemValue="5" itemLabel="Jun"/>
                                <f:selectItem itemValue="6" itemLabel="Jul"/>
                                <f:selectItem itemValue="7" itemLabel="Ago"/>
                                <f:selectItem itemValue="8" itemLabel="Set"/>
                                <f:selectItem itemValue="9" itemLabel="Out"/>
                                <f:selectItem itemValue="10" itemLabel="Nov"/>
                                <f:selectItem itemValue="11" itemLabel="Dez"/>
                            </h:selectOneMenu>
                        </t:column>
                        <t:column>&nbsp;</t:column>
                        <t:column>&nbsp;</t:column>

                        <t:column width="15%"><a4j:commandButton value="Pesquisar" action="#{ReceberBean.pesquisar}" reRender="tblVendaLancamentos"/></t:column>
                        <t:column width="35%"><h:commandButton value="Receber" action="#{ReceberBean.receber}"/></t:column>
                        <t:column>&nbsp;</t:column>
                        <t:column>&nbsp;</t:column>
                    </t:panelGrid>
                </rich:simpleTogglePanel>
                
                <rich:dataTable id="tblVendaLancamentos" value="#{ReceberBean.listaVendaLancamentos}" var="list"
                                width="95%" columnClasses="center" rowKeyVar="rowVar">
                    <rich:column width="45px" style="text-align:center;">
                        <f:facet name="header">
                            <h:selectBooleanCheckbox id="allCheck" onclick="CheckAll(document.receberPesq);" label="Receber"/>
                        </f:facet>
                        <h:selectBooleanCheckbox value="#{list.recebido}" disabled="#{list.recebido}" rendered="#{!rec.recebido}"/>
                        <h:graphicImage url="../../../_images/passed.gif" title="Recibo já foi emitido" rendered="#{list.recebido}"/>&nbsp;
                        <h:commandButton image="../../../_images/error.gif" title="Cancelar emissão de recibo" binding="#{ReceberBean.btnCancelar}" value="#{rowVar}" rendered="#{list.recebido}">
                            <a4j:support event="onclick" ajaxSingle="true" action="#{ReceberBean.cancelarRecebimento}" reRender="tblVendaLancamentos"/>
                        </h:commandButton>
                    </rich:column>

                    <rich:column style="text-align:center;">
                        <f:facet name="header">
                            <h:outputText value="Forma de Pagamento"/>
                        </f:facet>
                        <h:outputText value="#{list.formaPagamento.descricao}"/>
                    </rich:column>

                    <rich:column width="90px">
                        <f:facet name="header">
                            <h:outputText value="Data Recebido" styleClass="label"/>
                        </f:facet>
                        <rich:calendar id="dataPagamento" popup="true" datePattern="dd/MM/yyyy" inputSize="7" enableManualInput="false" value="#{list.dataPagamento}" rendered="true"/>
                    </rich:column>

                    <rich:column width="90px" style="text-align:center;">
                        <f:facet name="header">
                            <h:outputText value="Data Vencimento"/>
                        </f:facet>
                        <h:outputText value="#{list.dataVencimento}"/>
                    </rich:column>

                    <rich:column sortBy="#{list.valor}" style="text-align:right;">
                        <f:facet name="header">
                            <h:outputText value="Valor"/>
                        </f:facet>
                        <h:outputText value="#{list.valor}"><f:convertNumber pattern="#,##0.00"/></h:outputText>
                    </rich:column>

                    <rich:column width="50px" style="text-align:center;">
                        <f:facet name="header">
                            <h:outputText value="Parcela"/>
                        </f:facet>
                        <h:outputText value="#{list.numParcela}/#{list.venda.qtdParcelas}"></h:outputText>
                    </rich:column>

                    <rich:column width="50px" style="text-align:center;">
                        <f:facet name="header">
                            <h:outputText value="Cód Venda"/>
                        </f:facet>
                        <h:outputText value="#{list.venda.id}"></h:outputText>
                    </rich:column>
                </rich:dataTable>
            </h:form>
            <a4j:status id="modalStatus" onstart="Richfaces.showModalPanel('ajaxLoadingModalBox')"
            onstop="Richfaces.hideModalPanel('ajaxLoadingModalBox')" />
            <rich:modalPanel id="ajaxLoadingModalBox" zindex="20000" autosized="true">
                <h:outputText value="Carregando"/><br>
                <h:graphicImage value="../../../_images/img_load.gif"/>
            </rich:modalPanel>
        </f:view>
    </body>
</html>